Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sun.java.swing.text.AbstractDocument
This class implements a locking mechanism for the document. It
allows multiple readers or one writer, and writers must wait until
all observers of the document have been notified of a previous
change before beginning another mutation to the document. The
read lock is aquired and released using the render
method. A write lock is aquired by the methods that mutate the
document, and are held for the duration of the method call.
Notification is done on the thread that produced the mutation,
and the thread has full read access to the document for the
duration of the notification, but other readers are kept out
until the notification has finished. The notification is a
beans event notification which does not allow any further
mutations until all listeners have been notified.
Any models subclassed from this class and used in conjunction
with a text component that has a look and feel implementation
that is derived from DefaultTextUI may be safely updated
asynchronously. The rendering in DefaultTextUI occurs under
the protection of the render
method, which makes
rendering safe if it is running on the event thread (which
happens if using repaint to schedule updates). The code path
for any DocumentListener implementation must not access the
component lock if trying to be safe from deadlocks.
The revalidate
methods
on JComponent are safe.
Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
Inner Class Summary | |
AbstractDocument.AbstractElement
Implements the abstract part of an element. |
|
static | AbstractDocument.AttributeContext
An interface that can be used to allow MutableAttributeSet implementations to use pluggable attribute compression techniques. |
AbstractDocument.BranchElement
Implements a composite element that contains other elements. |
|
static | AbstractDocument.Content
Interface to describe a sequence of character content that can be edited. |
AbstractDocument.DefaultDocumentEvent
Stores document changes as the document is being modified. |
|
static | AbstractDocument.ElementEdit
An implementation of ElementChange that can be added to the document event. |
AbstractDocument.LeafElement
Implements an element that directly represents content of some kind. |
Field Summary | |
static java.lang.String | BAD_LOCATION
Error message to indicate a bad location. |
static java.lang.String | ContentElementName
Name of elements used to represent content |
static java.lang.String | ElementNameAttribute
Name of the attribute used to specify element names. |
EventListenerList | listenerList
The event listener list for the document. |
static java.lang.String | ParagraphElementName
Name of elements used to represent paragraphs |
static java.lang.String | SectionElementName
Name of elements used to hold sections (lines/paragraphs). |
Constructor Summary | |
AbstractDocument(AbstractDocument.Content data)
Constructs a new AbstractDocument, wrapped around some specified content storage mechanism. |
|
AbstractDocument(AbstractDocument.Content data,
AbstractDocument.AttributeContext context)
Constructs a new AbstractDocument, wrapped around some specified content storage mechanism. |
Method Summary | |
void | addDocumentListener(DocumentListener listener)
Adds a document listener for notification of any changes. |
void | addUndoableEditListener(UndoableEditListener listener)
Adds an undo listener for notification of any changes. |
Element | createBranchElement(Element parent,
AttributeSet a)
Creates a document branch element, that can contain other elements. |
Element | createLeafElement(Element parent,
AttributeSet a,
int p0,
int p1)
Creates a document leaf element. |
Position | createPosition(int offs)
Returns a position that will track change as the document is altered. |
void | dump(java.io.PrintStream out)
Gives a diagnostic dump. |
void | fireChangedUpdate(DocumentEvent e)
Notifies all listeners that have registered interest for notification on this event type. |
void | fireInsertUpdate(DocumentEvent e)
Notifies all listeners that have registered interest for notification on this event type. |
void | fireRemoveUpdate(DocumentEvent e)
Notifies all listeners that have registered interest for notification on this event type. |
void | fireUndoableEditUpdate(UndoableEditEvent e)
Notifies all listeners that have registered interest for notification on this event type. |
AbstractDocument.AttributeContext | getAttributeContext()
Fetches the context for managing attributes. |
AbstractDocument.Content | getContent()
Gets the content for the document. |
java.lang.Thread | getCurrentWriter()
Fetches the current writing thread if there is one. |
Element | getDefaultRootElement()
Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided. |
java.util.Dictionary | getDocumentProperties()
Support for managing a set of properties. |
Position | getEndPosition()
Returns a position that represents the end of the document. |
int | getLength()
Returns the length of the data. |
java.lang.Object | getProperty(java.lang.Object key)
A convenience method for looking up a property value. |
Element[] | getRootElements()
Gets all root elements defined. |
Position | getStartPosition()
Returns a position that represents the start of the document. |
java.lang.String | getText(int offset,
int length)
Gets a sequence of text from the document. |
void | getText(int offset,
int length,
Segment txt)
Gets some text from the document potentially without making a copy. |
void | insertString(int offs,
java.lang.String str,
AttributeSet a)
Inserts some content into the document. |
void | insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
AttributeSet attr)
Updates document structure as a result of text insertion. |
void | putProperty(java.lang.Object key,
java.lang.Object value)
A convenience method for storing up a property value. |
void | readLock()
Acquires a lock to begin reading some state from the document. |
void | readUnlock()
Does a read unlock. |
void | remove(int offs,
int len)
Removes some content from the document. |
void | removeDocumentListener(DocumentListener listener)
Removes a document listener. |
void | removeUndoableEditListener(UndoableEditListener listener)
Removes an undo listener. |
void | removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
Updates any document structure as a result of text removal. |
void | render(java.lang.Runnable r)
This allows the model to be safely rendered in the presence of currency, if the model supports being updated asynchronously. |
void | setDocumentProperties(java.util.Dictionary x)
Replace the document properties dictionary for this document. |
void | writeLock()
Acquires a lock to begin mutating the document this lock protects. |
void | writeUnlock()
Releases the write lock held because the write operation is finished. |
Methods inherited from class java.lang.Object | |
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
Field Detail |
protected EventListenerList listenerList
protected static final java.lang.String BAD_LOCATION
public static final java.lang.String ParagraphElementName
public static final java.lang.String ContentElementName
public static final java.lang.String SectionElementName
public static final java.lang.String ElementNameAttribute
Constructor Detail |
protected AbstractDocument(AbstractDocument.Content data)
data
- the contentprotected AbstractDocument(AbstractDocument.Content data, AbstractDocument.AttributeContext context)
data
- the content
context
- the attribute contextMethod Detail |
public java.util.Dictionary getDocumentProperties()
public void setDocumentProperties(java.util.Dictionary x)
x
- the new dictionaryprotected void fireInsertUpdate(DocumentEvent e)
e
- the eventprotected void fireChangedUpdate(DocumentEvent e)
e
- the eventprotected void fireRemoveUpdate(DocumentEvent e)
e
- the eventprotected void fireUndoableEditUpdate(UndoableEditEvent e)
e
- the eventpublic void render(java.lang.Runnable r)
This is implemented to aquire a read lock for the duration of the runnables execution. There may be multiple runnables executing at the same time, and all writers will be blocked while there are active rendering runnables. If the runnable throws an exception, its lock will be safely released. There is no protection against a runnable that never exits, which will effectively leave the document locked for it's lifetime.
If the given runnable attempts to make any mutations in this implementation, a deadlock will occur. There is no tracking of individual rendering threads to enable detecting this situation, but a subclass could incur the overhead of tracking them and throwing an error.
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
r
- the renderer to execute.public int getLength()
public void addDocumentListener(DocumentListener listener)
listener
- the listenerpublic void removeDocumentListener(DocumentListener listener)
listener
- the listenerpublic void addUndoableEditListener(UndoableEditListener listener)
listener
- the listenerpublic void removeUndoableEditListener(UndoableEditListener listener)
listener
- the listenerpublic final java.lang.Object getProperty(java.lang.Object key)
getDocumentProperties().get(key);
key
- the non-null property keypublic final void putProperty(java.lang.Object key, java.lang.Object value)
getDocumentProperties().put(key, value);If value is null this method will remove the property
key
- the non-null key
value
- the valuepublic void remove(int offs, int len) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
offs
- the starting offset >= 0
len
- the number of characters to remove >= 0public void insertString(int offs, java.lang.String str, AttributeSet a) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
offs
- the starting offset >= 0
str
- the string to insert; does nothing with null/empty strings
a
- the attributes for the inserted contentpublic java.lang.String getText(int offset, int length) throws BadLocationException
offset
- the starting offset >= 0
length
- the number of characters to retrieve >= 0public void getText(int offset, int length, Segment txt) throws BadLocationException
Segment
should never be mutated.
This kind of access to the characters of the document
is provided to help make the rendering potentially more
efficient. The caller should make no assumptions about
the lifetime of the returned character array, which
should be copied if needed beyond the use for rendering.
offset
- the starting offset >= 0
length
- the number of characters to retrieve >= 0
txt
- the Segment object to retrieve the text intopublic Position createPosition(int offs) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
offs
- the position in the model >= 0public final Position getStartPosition()
public final Position getEndPosition()
public Element[] getRootElements()
public abstract Element getDefaultRootElement()
protected final AbstractDocument.AttributeContext getAttributeContext()
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
chng
- a description of the change
attr
- the attributes for the changeprotected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
chng
- a description of the changepublic void dump(java.io.PrintStream out)
out
- the output streamprotected final AbstractDocument.Content getContent()
protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1)
parent
- the parent element
a
- the attributes for the element
p0
- the beginning of the range >= 0
p1
- the end of the range >= p0protected Element createBranchElement(Element parent, AttributeSet a)
parent
- the parent element
a
- the attributesprotected final java.lang.Thread getCurrentWriter()
protected final void writeLock()
protected final void writeUnlock()
protected final void readLock()
protected final void readUnlock()
Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |